﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Model.EntityModel;
using DataAccess;
using System.Drawing.Printing;
using System.Drawing;
using System.Collections.ObjectModel;

namespace Project
{
    /// <summary>
    /// Interaction logic for ViewCitationContent.xaml
    /// </summary>
    public partial class ViewCitationContent : UserControl
    {
        public long idComplaint;
        Actor ActorDenounced = new Actor();
        Person Denounced = new Person();
        Actor ActorAggressor = new Actor();
        Person Aggressor = new Person();
        Employee functionary = new Employee();
        Model.Functionary f = new Model.Functionary();
        Citation citation = new Citation();

        public ViewCitationContent(long id, long idCitation)
        {
            InitializeComponent();
            UIWindowManager.SetWindowTitle(this, "Brigada De Protección a la Familia - Ver Citación");
            try
            {
                citation = CitationDataAccess.GetCitationByIdCitation(idCitation);
                idComplaint = id;
                lblCaseNumber.Content = idComplaint;
                ActorDenounced = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Denunciante", idComplaint);
                Denounced = PersonAndActorDataAccess.GetPersonById(ActorDenounced.IdPerson);
                LblDenouncedName.Content = Denounced.Name+" "+Denounced.PaternalName+" "+ Denounced.MaternalName;               
                ActorAggressor = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Agresor", idComplaint);
                Aggressor = PersonAndActorDataAccess.GetPersonById(ActorAggressor.IdPerson);
                LblAggressorName.Content = Aggressor.Name+" "+Aggressor.PaternalName+" "+Aggressor.MaternalName;               
                f = DataBaseAccess.ReadEmployee(Convert.ToInt64(citation.IdEmployee));
                LblEmployeRank.Content = f.Rank + " " + f.Name + " " + f.PaternalName + " " + f.MaternalName;
                LblCitationDate.Content = citation.CitationDate;
                LblBoxHours.Content=citation.CitationTime.ToString();               
            }
            catch
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("No existe una citacion", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Loaded += KillApp;
            }
        }

        private void KillApp(object sender, RoutedEventArgs e)
        {
            UIWindowManager.CleanWindow(this);
        }

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            DrpDownPrintOptions.IsOpen = true;
        }

        private void Print_Click(object sender, RoutedEventArgs e)
        {
            var items = new ObservableCollection<UserControl>();
            items.Add(new PrintCitation(idComplaint,citation.Id));
            var a = new PrintPreviewDialogV2(items);
            a.MenuItem_Click(null, null);
        }

        private void PrintPreview_Click(object sender, RoutedEventArgs e)
        {
            var items = new ObservableCollection<UserControl>();
            items.Add(new PrintCitation(idComplaint,citation.Id));
            var a = new PrintPreviewDialogV2(items);
            a.ShowDialog();
        }
        
    }
}
